/*
 usage:compile this module by make
       load module by command "sudo insmod shrirq.ko irqn=1 devname=shrirq"
       irqn:irq number;devname:device name.
       irqn=1:interrupt share with i8042 keyboard controller(PS/2 port)
              usb keyboard use lsusb and cat /proc/interrupts to find.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>

static int irqn;
static char* devname;

module_param(irqn,int,0644);
module_param(devname,charp,0644);

struct shrirq
{
	int devid;
}shrdev={1119};

static irqreturn_t shrirq_handler(int irq,void * dev)
{
	static int count=0;
	struct shrirq shrdev=*(struct shrirq*)dev;

	printk("Enter shrirq_handler!\n");
	printk("ISR devid:%d\n",shrdev.devid);
	printk("count=%d\n",count);
	count++;
	if(count > 65536)
	      count=0;
	printk("Leaving IRQ handler!\n");
	return IRQ_HANDLED;
}

static int __init shrirq_init(void)
{
	printk("Enter shrirq_init...\n");
	if(request_irq(irqn,shrirq_handler,IRQF_SHARED,devname,&shrdev) != 0)
	{
		printk("Request IRQ failed!\ndevname=%s,IRQ:%d\n",devname,irqn);
		return -1;
	}
	printk("Request IRQ success!\ndevname=%s,IRQ:%d\n",devname,irqn);
        printk("Exit shrirq_init...\n");
	return 0;
}

static void __exit shrirq_exit(void)
{
	printk("Enter shrirq_exit...\n");
	free_irq(irqn,&shrdev);
	printk("Release irq sucess!\ndevname=%s,IRQ:%d\n",devname,irqn);
	printk("Exit shrirq_exit...\n");
}

module_init(shrirq_init);
module_exit(shrirq_exit);

MODULE_LICENSE("GPL");
